#include "QtGraphicsStateView.h"
#include "QtGraphicsStateItem.h"
#include "QtAnimGraphicsItem.h"

QtGraphicsStateView::QtGraphicsStateView(QWidget* parent/* = 0*/):
QGraphicsView(parent)
{
}

QtGraphicsStateView::QtGraphicsStateView(QGraphicsScene* scene, QWidget* parent/* = 0*/):
QGraphicsView(scene, parent)
{
}

QtGraphicsStateView::~QtGraphicsStateView(void)
{
}

void QtGraphicsStateView::createState()
{
	if (!scene())
	{
		return;
	}

	QtGraphicsStateItem* stateItem = new QtGraphicsStateItem;
	QtAnimGraphicsItem* pParentItem = dynamic_cast<QtAnimGraphicsItem*>(scene()->parent());
	QtTransform trans;
	trans._translate = pParentItem->getTransTranslate();
	trans._rotate = pParentItem->getTransRotate();
	trans._scale = pParentItem->getTransScale();
	stateItem->setState(trans);
	scene()->addItem(stateItem);
	connect(pParentItem->scene(), SIGNAL(playAnim(bool)), scene(), SLOT(playAnim(bool)));
	connect(scene(), SIGNAL(selected(const QPointF&, const QVector3D&, const QPointF&)), pParentItem, SLOT(stateSelected(const QPointF&, const QVector3D&, const QPointF&)));
	connect(pParentItem, SIGNAL(stateChanged(const QPointF&, const QVector3D&, const QPointF&)), scene(), SLOT(stateChanged(const QPointF&, const QVector3D&, const QPointF&)));
}


void QtGraphicsStateView::resizeEvent(QResizeEvent *event)
{
	QGraphicsView::resizeEvent(event);
	if (scene())
	{
		scene()->setSceneRect(rect());
	}
}
